piXoneer Development Library
XDL 3.0 for C#
NXImageView를 활용하여 여러 장의 GeoTIFF 파일을 도시하는 기능을 구현합니다.
자세한 설명은 "영상도시 툴 만들기 1"의 1. 예제 프로그램 만들기를 참고하기 바란다.
자세한 설명은 "영상도시 툴 만들기 1"의 1.5 참조추가 이후를 참고하기 바란다.
C#
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
}
C#
public XRasterIO m_RasterIO; //영상의 입출력을 담당할 객체 선언
C#
public Form1()
{
InitializeComponent();
String StrError;
m_RasterIO = new XRasterIO(); // 객체 생성
if (m_RasterIO.Initialize(out StrError) == false) // 영상 입출력 객체 초기화
{
MessageBox.Show(StrError);
}
nxImageLayerComposites1.LayerVisible = true; // 영상레이어를 보이도록 속성을 변경
}
C#
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
{
// 파일 Open을 수행한다.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "GeoTiff file(*.tif)|*.TIF||";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
string strFilePath = openFileDialog.FileName;
// FileDriverManger를 통해 XRSLoadFile을 생성한다.
// GeoTIFF 직접 로딩하는 경우 영상크기가 큰 경우 도시 속도를 위해서 LOD가 필요하기 때문에 필요한 경우 같은 폴더에 .xld파일을 생성한다.
string strError;
XRSLoadFile xrsFileInput1 = m_RasterIO.LoadFile(strFilePath, out strError, false, eIOCreateXLDMode.All_NoMsg);
if (xrsFileInput1 == null) return;
// 다시 Original Image에 대한 Composite와 Processed Image에 대한 Composite를 생성하여 뷰 컨트롤에 도시한다.
XDMComposite newComp = CreateComposite(xrsFileInput1, 0, 1, 2);
// 기존에 생성되어 있는 Composite가 있다면 Lock을 걸어 도시 수행을 잠시 멈춘다.
nxImageLayerComposites1.Lock();
// nxImageLayerComposites1개체에 있는 XDMCompManager들을 꺼낸다.
// XDMCompManager가 실제로 Composite들의 관리를 수행한다.
XDMCompManager xdmCompManager = nxImageLayerComposites1.GetXDMCompManager();
// 생성된 Composite를 XDMCompManager에 추가한다.
xdmCompManager.AddXDMComposite(ref newComp);
// 전체 화면 보기를 설정한다.
nxImageLayerComposites1.ZoomFit();
// 화면 업데이트를 수행한다.
nxImageLayerComposites1.Invalidate();
// Lock을 다시 풀어 준다.
nxImageLayerComposites1.UnLock();
}
C#
XDMComposite CreateComposite(XRSLoadFile xrsFileInput, int nBandIdx0, int nBandIdx1, int nBandIdx2)
{
// XDMComposite를 생성한다.
XDMComposite newComp = new XDMComposite();
// 로딩된 파일로부터 밴드의 개수가 칼라로 그릴 것인지 흑백으로 그릴 것인지를 판단한다.
// 만약 3개 미만인 경우는 Gray모드로 그리고, 3개 이상인 경우는 칼라로 그린다.
int nNumBand = xrsFileInput.NumBand;
if (nNumBand < 3) // 3개 미만의 밴드를 가지고 있는 경우
{
// Default로 0번째 밴드를 Gray모드로 그린다.
XDMBand band = xrsFileInput.GetBandAt(0);
// Gray Mode로 그리는 것을 설정
newComp.Mode = eCompMode.Gray;
// Composite의 0번에 Band설정, Gray모드에서는 0번 밴드만을 인식한다.
newComp.SetBand(ref band, nBandIdx0);
// 영상 Enhancement를 위해 Histogram의 범위 설정(정규분포 95% 영역)
newComp.SetCutType(eCompCutType.Ct95, 0);
// 영상 Enhancement를 위해 Histogram적용시 전체 영역에 대한
// Histogram(Band)설정, Visible은 현재 영역
newComp.SetStretchCoverage(eCompStretchCoverage.Band, 0);
// 영상 Enhancement를 위해 Histogram의 Stretch형태 설정(Gaussian으로 설정)
newComp.SetStretchType(eCompStretchType.Gaussian, 0);
}
else // 3개 이상의 밴드를 가지고 있는 경우
{
XDMBand band1 = xrsFileInput.GetBandAt(nBandIdx0);
XDMBand band2 = xrsFileInput.GetBandAt(nBandIdx1);
XDMBand band3 = xrsFileInput.GetBandAt(nBandIdx2);
newComp.Name = xrsFileInput.FileName; // 파일 이름을 Composite이름으로 설정
newComp.Mode = eCompMode.RGB; // RGB Mode로 그리는 것을 설정
newComp.SetBand(ref band3, nBandIdx0); // Composite의 0번에 Band설정, Blue Channel설정
newComp.SetBand(ref band2, nBandIdx1); // Composite의 1번에 Band설정, Green Channel설정
newComp.SetBand(ref band1, nBandIdx2); // Composite의 2번에 Band설정, Red Channel설정
for (int i = 0; i < 3; i++)
{
// 영상 Enhancement를 위해 Histogram의 범위 설정(정규분포 95% 영역)
newComp.SetCutType(eCompCutType.Ct95, i);
// 영상 Enhancement를 위해 Histogram적용시 전체 영역에 대한
// Histogram(Band)설정, Visible은 현재 영역
newComp.SetStretchCoverage(eCompStretchCoverage.Band, i);
// 영상 Enhancement를 위해 Histogram의 Stretch형태 설정(Gaussian으로 설정)
newComp.SetStretchType(eCompStretchType.Gaussian, i);
}
}
// 생성된 Composite를 XDMCompManager객체에 추가한다.
return newComp;
}
두 영상이 위치에 맞게 중첩된 결과를 확인할 수 있다.
자세한 설명은 "영상도시 툴 만들기 1"의 1. 예제 프로그램 만들기를 참고하기 바란다.
자세한 설명은 "영상도시 툴 만들기 1"의 1.5 참조추가 이후를 참고하기 바란다.
자세한 설명은 "영상도시 툴 만들기 1"의 1.7 항목을 참고하기 바란다.
Control type | Header | Name |
---|---|---|
MenuItem | _File | |
MenuItem | _Open | openFileMenuItem |
최종적으로 다음과 같은 XAML 코드를 생성한다.
XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Menu Grid.Row="0">
<MenuItem Header="_File" Margin="5,5,0,0">
<MenuItem x:Name="openFileMenuItem" Header="_Open"/>
</MenuItem>
</Menu>
</Grid>
C#
<Grid Grid.Row="1">
<WindowsFormsHost Margin="3,0,3,3">
<nxImage:NXImageView x:Name="nxImageView1">
</nxImage:NXImageView>
</WindowsFormsHost>
</Grid>
NXImageLayerComposites은 영상의 밴드들을 합성시켜서 화면에 도시하는 기능을 수행하는 컨트롤이다.
XAML
<Grid Grid.Row="1">
<WindowsFormsHost Margin="3,0,3,3">
<nxImage:NXImageView x:Name="nxImageView1">
<nxImage:NXImageView.Controls>
<nxImage:NXImageLayerComposites x:Name="nxImageLayerComposites1"/>
</nxImage:NXImageView.Controls>
</nxImage:NXImageView>
</WindowsFormsHost>
</Grid>
C#
private void openFileMenuItem_Click(object sender, RoutedEventArgs e)
{
}
C#
public XRasterIO m_RasterIO; //영상의 입출력을 담당할 객체 선언
C#
public MainWindow()
{
InitializeComponent();
String StrError;
m_RasterIO = new XRasterIO(); // 객체 생성
if (m_RasterIO.Initialize(out StrError) == false) // 영상 입출력 객체 초기화
{
MessageBox.Show(StrError);
}
NxImageLayerComposite1.LayerVisible = true; // 영상레이어를 보이도록 속성을 변경
}
C#
private void openFileMenuItem_Click(object sender, RoutedEventArgs e)
{
// 파일 Open을 수행한다.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "GeoTiff file(*.tif)|*.TIF||";
openFileDialog.RestoreDirectory = true;
Nullable<bool> result = openFileDialog.ShowDialog();
if (result != true) return;
string strFilePath = openFileDialog.FileName;
// FileDriverManger를 통해 XRSLoadFile를 생성한다.
// GeoTIFF를 직접 로딩하는 경우 영상 크기가 큰 경우 도시 속도를 위해서 LOD가 필요하기 때문에 필요한 경우 같은 폴더에 .xdl 파일을 생성한다.
string strError;
XRSLoadFile xrsFileInput1 = m_RasterIO.LoadFile(strFilePath, out strError,
false, eIOCreateXLDMode.All_NoMsg);
if (xrsFileInput1 == null) return;
// 다시 Original Imange에 대한 Composite와 Processed Image에 대한 Composite를 생성하여 뷰 컨트롤에 도시한다.
XDMComposite newComp = CreateComposite(xrsFileInput1, 0, 1, 2);
// 기존에 생성되어 있는 Composite가 있다면 Lock을 걸어 도시 수행을 잠시 멈춘다.
nxImageLayerComposites1.Lock();
// nxImageLayerCompostie1개체에 있는 XDMCompManager들을 꺼낸다.
// XDMCompManager가 실제로 Composite들의 관리를 수행한다.
XDMCompManager xdmCompManager = nxImageLayerComposites1.GetXDMCompManager();
// 생성된 Compostie를 XDMCompManager에 추가한다.
xdmCompManager.AddXDMComposite(ref newComp);
// 전체 화면 보기를 설정한다.
nxImageLayerComposites1.ZoomFit();
// 화면 업데이트를 수행한다.
nxImageLayerComposites1.Invalidate();
// Lock을 다시 풀어 준다.
nxImageLayerComposites1.UnLock();
}
C#
XDMComposite CreateComposite(XRSLoadFile xrsFileInput, int nBandIdx0, int nBandIdx1, int nBandIdx2)
{
// XDMComposite를 생성한다.
XDMComposite newComp = new XDMComposite();
// 로딩된 파일로부터 밴드의 개수가 칼라로 그릴 것인지 흑백으로 그릴 것인지 판단한다.
// 만약 3개 미만인 경우에는 Gray모드로 그리고, 3개 이상인 경우는 칼라로 그린다.
int nNumBand = xrsFileInput.NumBand;
if (nNumBand < 3) // 3개 미만의 밴드를 가지고 있는 경우
{
// Default로 0번째 밴드를 Gray 모드로 그린다.
XDMBand band = xrsFileInput.GetBandAt(0);
// Gray Mode로 그리는 것을 설정
newComp.Mode = eCompMode.Gray;
// Composite의 0번에 Band 설정, Gray 모드에서는 0번 밴드만을 인식한다.
newComp.SetBand(ref band, nBandIdx0);
// 영상 Enhancement를 위해 Histogram의 범위 설정 (정규분포 95% 영역)
newComp.SetCutType(eCompCutType.Ct95, 0);
// 영상 Enhancement를 위해 Histogram 적용 시 전체 영역에 대한 Histogram(Band) 설정, Visible은 현재 영역
newComp.SetStretchCoverage(eCompStretchCoverage.Band, 0);
// 영상 Enhancement를 위해 Histogram의 Stretch형태 설정(Gaussian으로 설정)
newComp.SetStretchType(eCompStretchType.Gaussian, 0);
}
else // 3개 이상의 밴드를 가지고 있는 경우
{
XDMBand band1 = xrsFileInput.GetBandAt(nBandIdx0);
XDMBand band2 = xrsFileInput.GetBandAt(nBandIdx1);
XDMBand band3 = xrsFileInput.GetBandAt(nBandIdx2);
// 파일 이름을 Composite이름으로 설정
newComp.Name = xrsFileInput.FileName;
newComp.Mode = eCompMode.RGB; // RGB Mode로 그리는 것을 설정
newComp.SetBand(ref band3, nBandIdx0); // Composite의 0번에 Band설정, Blue Channel 설정
newComp.SetBand(ref band2, nBandIdx1); // Composite의 1번에 Band설정, Green Channel 설정
newComp.SetBand(ref band1, nBandIdx2); // Composite의 2번에 Band설정, Red Channel 설정
for (int i = 0; i < 3; i++)
{
// 영상 Enhancement를 위해 Histogram의 범위 설정(정규분포 95% 영역)
newComp.SetCutType(eCompCutType.Ct95, i);
// 영상 Enhancement를 위해 Histogram 적용 시 전체 영역에 대한
// Histogram(Band) 설정, Visible은 현재 영역
newComp.SetStretchCoverage(eCompStretchCoverage.Band, i);
// 영상 Enhancement를 위해 Histogram의 Stretch형태 설정(Gaussian으로 설정)
newComp.SetStretchType(eCompStretchType.Gaussian, i);
}
}
// 생성된 Composite를 XDMCompManager 객체에 추가한다.
return newComp;
}
두 영상이 위치에 맞게 중첩된 결과를 확인할 수 있다.